package cn.zyq.ykb.service.task.impl;

import cn.zyq.ykb.system.common.BaseService;
import com.github.pagehelper.PageHelper;
import cn.zyq.ykb.system.ry.util.SecurityUtils;
import cn.zyq.ykb.mapper.task.TaskPriceMapper;
import cn.zyq.ykb.beans.task.TaskPrice;
import cn.zyq.ykb.service.task.TaskPriceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.zyq.ykb.system.common.PageParam;
import com.github.pagehelper.PageInfo;


import java.time.LocalDateTime;
import java.util.UUID;
import java.util.List;

/**
 * 任务调价Service业务层处理
 *
 * @author SystemAuth
 * @date 2023-11-28
 */
@Service
public class TaskPriceServiceImpl  extends BaseService implements TaskPriceService {

    @Autowired
    private TaskPriceMapper taskPriceMapper;

    /**
     * 查询任务调价
     *
     * @param taskPriceID 任务调价主键
     * @return 任务调价
     */
    @Override
    public TaskPrice selectTaskPriceByTaskPriceID(Integer taskPriceID) {
        TaskPrice taskPrice = taskPriceMapper.selectByPrimaryKey(taskPriceID);
        if (taskPrice.getDeleted() == 1) {
            return null;
        }
        return taskPrice;
    }

    /**
     * 查询任务调价
     *
     * @param serviceID 业务ID
     * @return 任务调价
     */
    @Override
    public TaskPrice selectTaskPriceByServiceID(String serviceID) {
        TaskPrice param = new TaskPrice();
        param.setDeleted(0);
        param.setServiceID(serviceID);
        return this.taskPriceMapper.selectOne(param);
    }

    /**
     * 查询任务调价列表
     *
     * @param pageParam
     * @return 任务调价
     */
    @Override
    public PageInfo<TaskPrice> selectTaskPriceList(PageParam pageParam) {
        PageHelper.startPage(pageParam.getPage(), pageParam.getPageSize());
        pageParam.getKv().put("deleted", 0);
        List<TaskPrice> list = this.taskPriceMapper.list(pageParam.getKv());
        return new PageInfo<>(list);
    }

    /**
     * 查询任务调价列表
     *
     * @param pageParam
     * @return 任务调价
     */
    @Override
    public List<TaskPrice> selectTaskPriceAllList(PageParam pageParam) {
        PageHelper.startPage(pageParam.getPage(), pageParam.getPageSize());
        pageParam.getKv().put("deleted", 0);
        return this.taskPriceMapper.list(pageParam.getKv());
    }
    /**
     * 新增任务调价
     *
     * @param param 任务调价
     * @return 结果
     */
    @Override
    public int insertTaskPrice(TaskPrice param) {
        this.setCreateBaseData(param, SecurityUtils.getLoginUser().getSysAdmin());
        return this.taskPriceMapper.insertSelective(param);
    }

    /**
     * 修改任务调价
     *
     * @param param 任务调价
     * @return 结果
     */
    @Override
    public int updateTaskPrice(TaskPrice param) {
        this.setUpdateBaseData(param, SecurityUtils.getLoginUser().getSysAdmin());
        return this.taskPriceMapper.updateByPrimaryKeySelective(param);
    }

    /**
     * 批量删除任务调价
     *
     * @param taskPriceIDs 需要删除的任务调价主键
     * @return 结果
     */
    @Override
    public int deleteTaskPriceByTaskPriceIDs(Integer[] taskPriceIDs) {
        int i = 0;
        for (Integer taskPriceID : taskPriceIDs) {
            i += this.deleteTaskPriceByTaskPriceID(taskPriceID);
        }
        return i;
    }

    /**
     * 删除任务调价信息
     *
     * @param taskPriceID 任务调价主键
     * @return 结果
     */
    @Override
    public int deleteTaskPriceByTaskPriceID(Integer taskPriceID) {
        TaskPrice taskPrice = this.selectTaskPriceByTaskPriceID(taskPriceID);
        if (taskPrice == null) {
            return 0;
        } else {
            TaskPrice storeInfo = new TaskPrice();
            storeInfo.setTaskPriceID(taskPriceID);
            storeInfo.setDeleted(1);
            storeInfo.setUpdateTime(LocalDateTime.now());
            this.taskPriceMapper.updateByPrimaryKeySelective(storeInfo);
            return 1;
        }
    }
}
